package schema

import (
	"lianzi_gos/internal/config"
	"time"

	"lianzi_gos/pkg/util"
)

// 员工表
type Staff struct {
	ID          string    `json:"id" gorm:"size:20;primarykey;"` // Unique ID
	Name        string    `json:"name"  gorm:"size:20;comment:'昵称';default:''"`
	UID         string    `json:"uid"  gorm:"size:20;comment:'用户ID';default:''"`
	Avatar      string    `json:"avatar"  gorm:"size:200;comment:'头像';default:''"`
	Position    string    `json:"position"  gorm:"size:20;comment:'职位';default:''"`
	Address     string    `json:"address"  gorm:"size:120;comment:'住址';default:''"`
	Email       string    `json:"email"  gorm:"size:120;comment:邮箱;default:"`
	Wxname      string    `json:"wxname"  gorm:"size:30;comment:'企业微信名称';default:''"`
	Status      string    `json:"status"  gorm:"size:20;comment:enabled, disabled;default:enabled"`
	Phone       string    `json:"phone"  gorm:"unique;size:20;index;comment:'手机号';default:''"`
	Auth        int64     `json:"auth"  gorm:"index;comment:'1 普通 2 管理';default:1"`
	Description string    `json:"description" gorm:"size:1024"` // Details about dictionary
	CreatedAt   time.Time `json:"created_at" gorm:"index;"`     // Create time
	UpdatedAt   time.Time `json:"updated_at" gorm:"index;"`     // Update time
}

func (a *Staff) TableName() string {
	return config.C.FormatTableName("staff")
}

// Defining the query parameters for the `Staff` struct.
type StaffQueryParam struct {
	util.PaginationParam
	Source int `form:"source"` // 0 普通 1 过滤掉  auth
}

// Defining the query options for the `Staff` struct.
type StaffQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Staff` struct.
type StaffQueryResult struct {
	Data       Staffs
	PageResult *util.PaginationResult
}

// Defining the slice of `Staff` struct.
type Staffs []*Staff

// Defining the data structure for creating a `Staff` struct.
type StaffForm struct {
	Name        string `json:"name" binding:"required"`                          // 昵称
	Wxname      string `json:"wxname" binding:"required"`                        // 昵称
	Avatar      string `json:"avatar" binding:"required"`                        //头像
	Phone       string `json:"phone" binding:"required"`                         // 手机
	Description string `json:"description"`                                      // Details about menu
	Email       string `json:"email"`                                            // Details about menu
	Position    string `json:"position"`                                         // Details about menu
	Address     string `json:"address"`                                          // Details about menu
	Status      string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
}

// A validation function for the `StaffForm` struct.
func (a *StaffForm) Validate() error {
	return nil
}

// Convert `StaffForm` to `Staff` object.
func (a *StaffForm) FillTo(staff *Staff) error {
	staff.Name = a.Name
	staff.Email = a.Email
	staff.Avatar = a.Avatar
	staff.Description = a.Description
	staff.Phone = a.Phone
	staff.Address = a.Address
	staff.Status = a.Status
	staff.Wxname = a.Wxname
	staff.Position = a.Position
	return nil
}
